package com.game.character;

import com.game.bullet.BulletManager;
import com.game.collision.CollisionCheck;
import com.game.framwork.gamesupport.GameSprite;
import com.game.framwork.itf.Graphics;
import com.game_ltdd.Resrouce;

public class Monster extends Mobs {

	public Monster(int typeMonster) {
		mobType = typeMonster;
		init();
	}

	public void init() {
		GameSprite[] pAnim;
		pAnim = new GameSprite[7];

		if (mobType == MOB_MUMMY) {
			this.objectImage = Resrouce.mummy;
			pAnim[0] = new GameSprite(objectImage);
			pAnim[0].createAnimation("Stand", 8, 8, 8, 1.0f);
			pAnim[1] = new GameSprite(objectImage);
			pAnim[1].createAnimation("Stand Animation", 0, 8, 0, 1.0f / 10.0f);
			pAnim[2] = new GameSprite(objectImage);
			pAnim[2].createAnimation("Move Left", 9, 14, 9, 1.0f / 10.0f);
			pAnim[3] = new GameSprite(objectImage);
			pAnim[3].createAnimation("Move Right", 15, 20, 15, 1.0f / 10.0f);
			pAnim[4] = new GameSprite(objectImage);
			pAnim[4].createAnimation("Move Top", 21, 26, 21, 1.0f / 10.0f);
			pAnim[5] = new GameSprite(objectImage);
			pAnim[5].createAnimation("Move Bot", 27, 31, 27, 1.0f / 6.0f);
			pAnim[6] = new GameSprite(objectImage);
			pAnim[6].createAnimation("Die", 27, 27, 27, 1.0f / 6.0f);

			loadSprite(objectImage, 32, 10, 56, 76, pAnim);
			createBoundBox(12, 15, 45, 30/* 20.0f, 20.0f, 30, 25 */);
		} else if (mobType == MOB_BAT) {
			this.objectImage = Resrouce.bat;
			pAnim[0] = new GameSprite(objectImage);
			pAnim[0].createAnimation("Stand", 17, 17, 17, 1.0f);
			pAnim[1] = new GameSprite(objectImage);
			pAnim[1].createAnimation("Stand Animation", 0, 6, 0, 1.0f / 6.0f);
			pAnim[2] = new GameSprite(objectImage);
			pAnim[2].createAnimation("Move Left", 7, 11, 7, 1.0f / 10.0f);
			pAnim[3] = new GameSprite(objectImage);
			pAnim[3].createAnimation("Move Right", 12, 16, 12, 1.0f / 10.0f);
			pAnim[4] = new GameSprite(objectImage);
			pAnim[4].createAnimation("Move Top", 17, 20, 17, 1.0f / 10.0f);
			pAnim[5] = new GameSprite(objectImage);
			pAnim[5].createAnimation("Move Bot", 21, 25, 21, 1.0f / 6.0f);
			pAnim[6] = new GameSprite(objectImage);
			pAnim[6].createAnimation("Die", 21, 21, 21, 1.0f / 6.0f);
			
			loadSprite(objectImage, 26, 10, 56, 62, pAnim);
			createBoundBox(9, 9, 35, 25);
		} else if (mobType == MOB_BOSS) {
			this.objectImage = Resrouce.boss;
			pAnim[0] = new GameSprite(objectImage);
			pAnim[0].createAnimation("Stand", 15, 15, 15, 1.0f);
			pAnim[1] = new GameSprite(objectImage);
			pAnim[1].createAnimation("Stand Animation", 15, 15, 15, 1.0f / 4.0f);
			pAnim[2] = new GameSprite(objectImage);
			pAnim[2].createAnimation("Move Left", 0, 4, 0, 1.0f / 10.0f);
			pAnim[3] = new GameSprite(objectImage);
			pAnim[3].createAnimation("Move Right", 5, 9, 5, 1.0f / 10.0f);
			pAnim[4] = new GameSprite(objectImage);
			pAnim[4].createAnimation("Move Top", 10, 14, 10, 1.0f / 10.0f);
			pAnim[5] = new GameSprite(objectImage);
			pAnim[5].createAnimation("Move Bot", 15, 19, 15, 1.0f / 6.0f);
			pAnim[6] = new GameSprite(objectImage);
			pAnim[6].createAnimation("Die", 15, 15, 15, 1.0f / 6.0f);
			
			loadSprite(objectImage, 32, 10, 56, 67, pAnim);
			createBoundBox(9, 20, 35, 25);
		}
	}

	private void shot(float deltaTime) {
		timeDelayShot += deltaTime;
		if (timeDelayShot >= timeMaxDelayShot) {
			BulletManager.getInstance().createBullet(this);
			timeDelayShot = 0f;
		}
	}
	
	@Override
	public void updateInternal(float deltaTime) {
		if (!isDeath && !isDying) {
			shot(deltaTime);
			timeToChangeDir += deltaTime;
			if (currState == 0) {
				this.changeAnimation("Stand");
			}
			randomMove();
			CollisionCheck.collisionOnMap(this, tiledMap);
			CollisionCheck.collisionWithBullet(this, BulletManager.getInstance().listBulletOfPlayer);
		} else if (isDying){
			dying(deltaTime);
		}
		super.updateInternal(deltaTime);
	}
	
	private void dying(float deltaTime) {
		changeAnimation("Die");
		dieTime += deltaTime;
		if (dieTime >= maxDieTime) {
			dieTime = 0.0f;
			isDeath = true;
		}
	}

	@Override
	public void paintInternal(Graphics g) {
		if (!isDeath) {
			super.paintInternal(g);
		}
	}
}
